import { useModel } from "umi";
import { useReactive } from "ahooks";
import { Modal } from "antd";

const userAddPersonVersion = () => {
    const { remoteData, BNTApplicationResourceCenterServiceURL } = useModel("global");
    const { baseInfo } = useModel("person.info");

    const state = useReactive({
        loading: false,
        versions: [],
    });

    const addVersion = async (callback) => {
        Modal.confirm({
            content: `确认要添加新版本信息吗?`,
            okButtonProps: { loading: state.loading },
            onOk: async () => {
                state.loading = true;
                let res = await remoteData({
                    object: "bnt-application-resource-center-service",
                    serviceUrl: BNTApplicationResourceCenterServiceURL,
                    serviceName: "/resource/referenceDatabase/person/addVersion",
                    params: {
                        creater: {
                            uuid: baseInfo.uuid,
                            name: baseInfo.realName,
                        },
                    },
                });
                res && callback && callback(res);
                state.loading = false;
            },
        });
    };

    return { ...state, addVersion };
};

export default userAddPersonVersion;
